<?php

class Bbling_IndexController extends Evebit_Controller_Action_Frontend {
	
	/**
	 * user's home page
	 */
	public function indexAction() {
	}
	
	public function entrepreneurProfileViewAction() {
		$user = Zend_Auth::getInstance ()->getIdentity ();
		$businessEntity = new Bbling_Model_Entity_Business ();
		$businessEntity->load ( $user->id, 'user_id' );
		
		if ($businessEntity->id) {
			$balanaceEntity = new Bbling_Model_Entity_Balanace ();
			$balanaceDatas = $balanaceEntity->getFinancialIdDatas ( array ('financial_id' => $businessEntity->financial_id ) );
			if (count ( $balanaceDatas )) {
				$arrayHelper = new Evebit_Array_Helper ();
				$balanaceDatas = $arrayHelper->arrayFilter ( $balanaceDatas, array ('id', 'financial_id' ) );
			}
		}else{
			$balanaceDatas = array();
		}
		
		$configEntity = new Default_Model_Entity_Config ();
		$paypalFee = $configEntity->getCodeValue ( 'paypal_fee' );
		$paypalAccount = $configEntity->getCodeValue ( 'paypal_account' );
		
		$emailHelper = new Evebit_Email_Helper ();
		$fullBasePath = $emailHelper->getFullBasePath ();
		
		$this->view->user = $user;
		$this->view->data = $businessEntity;
		$this->view->balanaceDatas = $balanaceDatas;
		$this->view->paypalFee = $paypalFee;
		$this->view->paypalAccount = $paypalAccount;
		$this->view->fullBasePath = $fullBasePath;
		
		/*CREATE CV FILE DOWNLOAD LINKS PARAMS 
		 *MODIFY BY MaXiaoHui 
		 */
		$data = $businessEntity->getData ();
		
		if (isset ( $data ['company_cv_files'] )) {
			$cv_files_str = $data ['company_cv_files'];
			
			$file_arr = null;
			$file_owner_str = null;
			
			$a = explode ( ';', $cv_files_str );
			array_pop ( $a );
			foreach ( $a as $items ) {
				$item = explode ( '@@', $items );
				$file_arr .= $item [0] . ';';
				
				$file_owner_str .= $item [1] . ';';
			}
			$cv_files_str = $file_arr;
			$cv_files_arr = explode ( ';', $cv_files_str );
			// POP THE LAST ELEMENT IN THE ARRAY BECAUST IT IS EMPTY
			array_pop ( $cv_files_arr );
			
			$cv_files_owner_arr = explode ( ';', $file_owner_str );
			// POP THE LAST ELEMENT IN THE ARRAY BECAUST IT IS EMPTY
			array_pop ( $cv_files_owner_arr );
			
			$cv_files_name_arr = $cv_files_arr; //store the cv files name;
			$key = 'http://www.evebit.com?year=2011';
			$hmac = new Evebit_Crypt_Hmac ( $key );
			foreach ( $cv_files_arr as &$value ) {
				$value = str_replace ( ' ', '', $value );
				$params = array ('cv_filename' => $value );
				$value = $hmac->createParam ( $params );
			}
			$this->view->cv_download_name_arr = $cv_files_name_arr;
			$this->view->cv_download_arr = $cv_files_arr;
			$this->view->cv_download_owner_name = $cv_files_owner_arr;
		}
	
	}
	
	public function entrepreneurProfileInvestorViewAction() {
		$user = Zend_Auth::getInstance ()->getIdentity ();
		$id = $this->getRequest ()->getParam ( 'id' );
		
		$businessEntity = new Bbling_Model_Entity_Business ();
		$businessEntity->load ( $id );
		if (! count ( $businessEntity->getData () )) {
			$this->getSession ()->addError ( $this->__ ( 'The resource has been deleted!' ) );
			$this->_redirect ( '/bbling/index/investor-profile' );
		}
		
		$userEntity = new User_Model_Entity_User ();
		$planUsername = $userEntity->load ( $businessEntity->user_id )->username;
		
		$balanaceEntity = new Bbling_Model_Entity_Balanace ();
		$balanaceDatas = $balanaceEntity->getFinancialIdDatas ( array ('financial_id' => $businessEntity->financial_id ) );
		if (count ( $balanaceDatas )) {
			$arrayHelper = new Evebit_Array_Helper ();
			$balanaceDatas = $arrayHelper->arrayFilter ( $balanaceDatas, array ('id', 'financial_id' ) );
		}
		
		$this->view->user = $user;
		$this->view->data = $businessEntity;
		$this->view->planUsername = $planUsername;
		$this->view->balanaceDatas = $balanaceDatas;
		
		/*CREATE CV FILE DOWNLOAD LINKS PARAMS 
		 *MODIFY BY MaXiaoHui 
		 */
		$data = $businessEntity->getData ();
		
		if (isset ( $data ['company_cv_files'] )) {
			$cv_files_str = $data ['company_cv_files'];
			$file_arr = null;
			$file_owner_str = null;
			
			$a = explode ( ';', $cv_files_str );
			array_pop ( $a );
			foreach ( $a as $items ) {
				$item = explode ( '@@', $items );
				$file_arr .= $item [0] . ';';
				$file_owner_str .= $item [1] . ';';
			}
			$cv_files_str = $file_arr;
			$cv_files_arr = explode ( ';', $cv_files_str );
			// POP THE LAST ELEMENT IN THE ARRAY BECAUST IT IS EMPTY
			array_pop ( $cv_files_arr );
			
			$cv_files_owner_arr = explode ( ';', $file_owner_str );
			// POP THE LAST ELEMENT IN THE ARRAY BECAUST IT IS EMPTY
			array_pop ( $cv_files_owner_arr );
			
			$cv_files_name_arr = $cv_files_arr; //store the cv files name;
			$key = 'http://www.evebit.com?year=2011';
			$hmac = new Evebit_Crypt_Hmac ( $key );
			foreach ( $cv_files_arr as &$value ) {
				$value = str_replace ( ' ', '', $value );
				$params = array ('cv_filename' => $value );
				$value = $hmac->createParam ( $params );
			
			}
			$this->view->cv_download_name_arr = $cv_files_name_arr;
			$this->view->cv_download_arr = $cv_files_arr;
			$this->view->cv_download_owner_name = $cv_files_owner_arr;
		
		//$this->view->cv_download_str = implode('|', $cv_files_arr);
		}
	}
	
	public function roleUpdateAction($key = null) {
		//$key = $this->getRequest ()->getParam ( "key", '' );
		$user = new User_Model_Entity_User ();
		if ($key == '' || $key == null || ! $user->isConfirmkeyValid ( $key )) {
			return false;
		}
		$user->load ( $key, 'confirm_key' );
		try {
			if ($user->select_role == 'Entrepenuer') {
				$user->unsetData ( 'password' );
				$user->setData ( 'select_role', 'Entrepenuer Pay' );
				$user->save ();
				return $user;
			} else {
				return false;
			}
		} catch ( Exception $e ) {
			return false;
		}
	}
	
	public function deleteListAction() {
		$user = Zend_Auth::getInstance ()->getIdentity ();
		$id = $this->getRequest ()->getParam ( 'id' );
		
		if ($user->select_role == 'Investor') {
			$listEntity = new Bbling_Model_Entity_List ();
			$listEntity->addData ( array ('id' => $id ) );
			try {
				$listEntity->delete ();
				$this->getSession ()->addSuccess ( $this->__ ( 'Delete succeed' ) );
			} catch ( Exception $e ) {
				$this->getSession ()->addError ( $this->__ ( 'Delete failed' ) );
			}
			$this->_redirect ( '/bbling/index/investor-profile' );
		}
	}
	
	public function addListAction() {
		$user = Zend_Auth::getInstance ()->getIdentity ();
		$id = $this->getRequest ()->getParam ( 'id' );
		
		if ($user->select_role == 'Investor') {
			$data = array ('user_id' => $user->id, 'business_id' => $id );
			$listEntity = new Bbling_Model_Entity_List ();
			if (! $listEntity->getResource ()->getId ( $data )) {
				$listEntity->addData ( $data );
				try {
					$listEntity->save ();
					$this->getSession ()->addSuccess ( $this->__ ( 'Add succeed' ) );
				} catch ( Exception $e ) {
					$this->getSession ()->addError ( $this->__ ( 'Add failed' ) );
				}
			} else {
				$this->getSession ()->addError ( $this->__ ( 'Add failed! You already added it' ) );
			}
			$this->_redirect ( '/bbling/index/investor-profile' );
		
		}
	}
	
	public function paypalNotifyAction() {
		// read the post from PayPal system and add 'cmd'
		$req = 'cmd=_notify-validate';
		
		foreach ( $_POST as $key => $value ) {
			$value = urlencode ( stripslashes ( $value ) );
			$req .= "&$key=$value";
		}
		
		// post back to PayPal system to validate
		$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
		$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
		$header .= "Content-Length: " . strlen ( $req ) . "\r\n\r\n";
		
		// If testing on Sandbox use:
		$fp = fsockopen ( 'ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30 );
		//$fp = fsockopen ( 'ssl://www.paypal.com', 443, $errno, $errstr, 30 );
		

		if (! $fp) {
			// HTTP ERROR
		} else {
			fputs ( $fp, $header . $req );
			while ( ! feof ( $fp ) ) {
				$res = fgets ( $fp, 1024 );
				if (strcmp ( $res, "VERIFIED" ) == 0) {
					// check the payment_status is Completed
					// check that txn_id has not been previously processed
					// check that receiver_email is your Primary PayPal email
					// check that payment_amount/payment_currency are correct
					// process payment
					if ($_POST ['mc_currency'] == 'GBP' && $_POST ['mc_gross'] == 45 && strtolower ( $_POST ['payment_status'] ) == 'completed') {
						$key = $_POST ['custom'];
						$user = $this->roleUpdateAction ( $key );
						if (is_object ( $user )) {
							$paymentEntity = new Bbling_Model_Entity_Payment ();
							//$data ['receiver_email'] = $_POST ['receiver_email'];
							$data ['txn_id'] = $_POST ['txn_id'];
							$data ['gross'] = $_POST ['mc_gross'];
							$data ['datetime'] = date ( "Y-m-d H:i:s", time () );
							$data ['quantity'] = $_POST ['quantity'];
							$data ['status'] = $_POST ['payment_status'];
							$data ['user_id'] = $user->id;
							$paymentEntity->addData ( $data );
							$paymentEntity->save ();
							$a = null;
							foreach ( $_POST as $key => $value ) {
								$a .= '@@' . $key . '@@@' . $value;
							}
							mail ( '853807856@qq.com', 'Content', $a );
						}
					} else {
						return false;
					}
				
				} else if (strcmp ( $res, "INVALID" ) == 0) {
					// log for manual investigation
				

				}
			}
			fclose ( $fp );
		}
	
	}
	
	public function deletePlanAction() {
		$id = $this->getRequest ()->getParam ( 'id' );
		$businessEntity = new Bbling_Model_Entity_Business ();
		$businessEntity->load ( $id );
		try {
			$businessEntity->delete ();
			$this->getSession ()->addSuccess ( $this->__ ( 'Delete succeed' ) );
		} catch ( Exception $e ) {
			$this->getSession ()->addError ( $this->__ ( 'Delete failed' ) );
		}
		$configEntity = new Default_Model_Entity_Config ();
		$this->_redirect ( $configEntity->getCodeValue ( 'wp_base_url' ) );
		;
	}
	
	public function businessPlanBuilderAction() {
		$payment = new Bbling_Model_Entity_Payment ();
		ini_set ( 'magic_quotes_gpc', 0 );
		
		$user = Zend_Auth::getInstance ()->getIdentity ();
		
		$IsAjax = $this->getRequest ()->getParam ( 'ajax' );
		$datas = $this->getRequest ()->getPost ( 'data' );
		$q = $this->getRequest ()->getParam ( 'q' );
		
		$businessEntity = new Bbling_Model_Entity_Business ();
		if ($IsAjax) {
			$businessEntity->addData ( $datas );
			$businessEntity->save ();
			
			$chartDatas = $this->getRequest ()->getPost ( 'chart' );
			if (count ( $chartDatas )) {
				$chartDatas ['id'] = $datas ['id'];
				$businessEntity->unsetData ();
				$businessEntity->addData ( $chartDatas );
				try {
					$saleDatas = $this->getRequest ()->getPost ( 'month' );
					$businessEntity->saveBalanaceDatas ( $saleDatas );
					echo 'Save succeed';
				} catch ( Exception $e ) {
					echo 'Save failed';
				}
				exit ();
			}
		}
		
		if (count ( $datas )) {
			$origData = $businessEntity->load ( $datas ['id'] )->getData ();
			$datas ['company_cv_files'] = isset ( $origData ['company_cv_files'] ) ? $origData ['company_cv_files'] : null;
			$businessEntity->unsetData ();
			$cvFile = $this->getRequest ()->getPost ( 'cv_file' );
			$cvName = $this->getRequest ()->getPost ( 'cv_name' );
			if (count ( $cvFile ) == count ( $cvName )) {
				for($i = 0; $i < count ( $cvFile ); $i ++) {
					$datas ['company_cv_files'] .= $cvFile [$i] . '@@' . $cvName [$i] . ';';
				}
			}
			$businessEntity->addData ( $datas );
			
			try {
				$businessEntity->save ();
				$this->getSession ()->addSuccess ( $this->__ ( 'Save succeed' ) );
				if ($q) {
					$this->_redirect ( 'http://businessandbling.co.uk/communityqa/' );
				} else {
					$this->_redirect ( '/bbling/index/entrepreneur-profile-view' );
				}
			} catch ( Exception $e ) {
				$this->getSession ()->addError ( $this->__ ( 'Save failed' ) );
			}
		}
		
		$businessEntity->load ( $user->id, 'user_id' );
		
		$configEntity = new Default_Model_Entity_Config ();
		$paypalFee = $configEntity->getCodeValue ( 'paypal_fee' );
		$paypalAccount = $configEntity->getCodeValue ( 'paypal_account' );
		
		$emailHelper = new Evebit_Email_Helper ();
		$fullBasePath = $emailHelper->getFullBasePath ();
		
		$locations = $businessEntity->getSpecialType ( 'location', true, false, null, 'location' );
		$industryTypes = $businessEntity->getSpecialType ( 'industry', true );
		$stateTypes = $businessEntity->getSpecialType ( 'state', true );
		
		$balanaceEntity = new Bbling_Model_Entity_Balanace ();
		$fileds = $balanaceEntity->getResource ()->getTableFields ();
		$monthName = array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jul', 'Jun', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );
		$this->view->unsetFileds = array ('financial_id', 'month', 'sales', 'cost_off' );
		$this->view->fileds = $fileds;
		$this->view->months = $monthName;
		
		$this->view->user = $user;
		$this->view->locations = $locations;
		$this->view->paypalFee = $paypalFee;
		$this->view->paypalAccount = $paypalAccount;
		$this->view->stateTypes = $stateTypes;
		$this->view->industryTypes = $industryTypes;
		$this->view->fullBasePath = $fullBasePath;
		$this->view->data = $businessEntity->getData ();
		
		$data = $businessEntity->getData ();
		$company_cv_files_arr = array ();
		if (isset ( $data ['company_cv_files'] )) {
			$company_cv_files_arr = explode ( ';', trim ( $data ['company_cv_files'] ) );
			
			/* POP THE LAST ELEMENT IN THE ARRAY BECAUST IT IS EMPTY*/
			array_pop ( $company_cv_files_arr );
		}
		
		$this->view->company_cv_files_arr = $company_cv_files_arr;
	
	}
	
	/**
	 * upload the CV file via ajax 
	 * @author: MaXiaoHui
	 */
	public function cvUploadAction() {
		// no render ,no layout
		$this->_helper->viewRenderer->setNoRender ( true );
		$this->_helper->layout->disableLayout ();
		
		// list of valid extensions, ex. array("jpeg", "xml", "bmp")
		$allowedExtensions = array ('rtf', 'doc', 'txt', 'pdf', 'docx' );
		// max file size in bytes
		$sizeLimit = 8 * 1024 * 1024;
		
		$uploader = new Evebit_Ajaxupload_Qqfileuploader ( $allowedExtensions, $sizeLimit );
		$result = $uploader->handleUpload ( RP . "/media/cvUpload/" );
		
		echo htmlspecialchars ( json_encode ( $result ), ENT_NOQUOTES );
	}
	
	/**
	 * delete the CV file via ajax
	 * @author: MaXiaoHui
	 */
	public function cvDeleteAction() {
		// no render ,no layout
		$this->_helper->viewRenderer->setNoRender ( true );
		$this->_helper->layout->disableLayout ();
		
		//security check
		

		/*
        * query whether the file is exists
        * delete the file if success and then update the table 
        * and then return result with a JSON 
        */
		
		/* $_POST include data_id , cv_delete_file , cv_files */
		
		//===============NOTICE SECURITY CHECK================//
		

		$filename = $this->getRequest ()->getPost ( 'cv_delete_file' );
		
		//$cv_files_exists = $this->getRequest ()->getPost( 'cv_files' );
		$data_id = $this->getRequest ()->getPost ( 'data_id' );
		$buisnessEntity = new Bbling_Model_Entity_Business ();
		$buisnessEntity->load ( $data_id );
		$cv_files_exists = $buisnessEntity->company_cv_files;
		
		$files = explode ( ';', $cv_files_exists );
		array_pop ( $files );
		$cv_files_new = null;
		foreach ( $files as $file ) {
			$item = explode ( '@@', $file );
			if ($item [0] == $filename) {
				continue;
			}
			$cv_files_new .= $file . ';';
		}
		
		$file = RP . '/media/cvUpload/' . $filename;
		if (file_exists ( $file )) {
			if (unlink ( $file )) {
				$companyEntity = new Bbling_Model_Entity_Company ();
				$companyEntity->addData ( array ('id' => $data_id, 'company_cv_files' => $cv_files_new ) );
				$companyEntity->updateFiles ();
			}
		}
		/* ALWAYS RETURN SUCCESS */
		
		$result = array ('result' => 'success' );
		echo Zend_Json::encode ( $result );
	}
	
	/**
	 * DOWNLOAD CV FILES ACTION
	 * @author: MaXiaoHui
	 */
	public function cvFilesDownloadAction() {
		
		//NOT RENDER , NO LAYOUT
		$this->_helper->viewRenderer->setNoRender ( true );
		$this->_helper->layout->disableLayout ();
		
		/* ==========SECURITY CHECK  NOT COMPLETE YET==========*/
		
		//$filename = $_POST['cv_filename'];
		

		if (isset ( $_GET ['cv_filename'], $_GET ['hash'] )) {
			$filename = str_replace ( ' ', '', $_GET ['cv_filename'] );
			$hash = str_replace ( ' ', '', $_GET ['hash'] );
			$verify_arr = array ('cv_filename' => $filename, 'hash' => $hash );
			$key = 'http://www.evebit.com?year=2011';
			$hmac = new Evebit_Crypt_Hmac ( $key );
			
			/*CHECK IF THE LINK IS VALID*/
			if ($hmac->verify_param ( $verify_arr )) {
				
				$downloadPath = RP . "/media/cvUpload/";
				
				/* CHECK WHETHER FILE EXISTS*/
				if (file_exists ( $downloadPath . $filename )) {
					/*OPEN FILE*/
					$file = fopen ( $downloadPath . $filename, "rb" );
					/*SETTING THE HEADER*/
					Header ( "Content-type: application/octet-stream" );
					Header ( "Accept-Ranges: bytes" );
					Header ( "Accept-Length: " . filesize ( $downloadPath . $filename ) );
					Header ( "Content-Disposition: attachment; filename=" . $filename );
					/*OUT PUT THE FILE*/
					echo fread ( $file, filesize ( $downloadPath . $filename ) );
					fclose ( $file );
					exit ();
				} else { /*FILE DOES NOT EXISTS*/
					die ( "File doesn't exist!" );
				}
			} else { /*ELSE THE LINK IS INVALID*/
				die ( 'Invalid download link!' );
			}
		} else { /* PARAM IS INVALID */
			die ( "File doesn't exist!" );
		}
	
	}
	
	public function searchAction() {
		$user = Zend_Auth::getInstance ()->getIdentity ();
		$searchs = $this->getRequest ()->getPost ( 'search' );
		
		$businessEntity = new Bbling_Model_Entity_Business ();
		$collection = $businessEntity->getCollection ();
		$collection->addFieldToFilter ( 'user_table.select_role', 'Entrepenuer Pay' );
		if ($searchs ['industry'] != '*') {
			$collection->addFieldToFilter ( 'financial_table.your_industry', $searchs ['industry'] );
		}
		if ($searchs ['state'] != '*') {
			$collection->addFieldToFilter ( 'financial_table.business_state', $searchs ['state'] );
		}
		if ($searchs ['fund'] != '*') {
			$fundEntity = new Bbling_Model_Entity_Fund ();
			$fundEntity->load ( $searchs ['fund'] );
			if ($fundEntity->to) {
				$collection->addFieldToFilter ( 'financial_table.funding_required', array ('moreq' => intval ( $fundEntity->from ) ) );
				$collection->addFieldToFilter ( 'financial_table.funding_required', array ('lteq' => intval ( $fundEntity->to ) ) );
			} else {
				$collection->addFieldToFilter ( 'financial_table.funding_required', array ('moreq' => intval ( $fundEntity->from ) ) );
			}
		}
		if (strtolower ( $searchs ['location'] ) != '*') {
			$collection->addFieldToFilter ( 'financial_table.your_location', array ('like' => '%' . $searchs ['location'] . '%' ) );
		}
		if (isset ( $searchs ['keywords'] )) {
			if ($searchs ['keywords'] != 'Key Word...')
				$collection->addFieldToFilter ( 'user_table.username', array ('like' => '%' . $searchs ['keywords'] . '%' ) );
		}
		$result = $collection->getItems ();
		$result = array_values ( $result );
		
		$industryTypes = $businessEntity->getSpecialType ( 'industry', true, true, 'All' );
		$stateTypes = $businessEntity->getSpecialType ( 'state', true, true, 'please choose:' );
		$locations = $businessEntity->getSpecialType ( 'location', true, true, 'please choose:', 'location' );
		$fundTypes = $businessEntity->getFundList ();
		
		$this->view->user = $user;
		$this->view->data = $result;
		$this->view->locations = $locations;
		$this->view->fundTypes = $fundTypes;
		$this->view->stateTypes = $stateTypes;
		$this->view->industryTypes = $industryTypes;
		
		//ADD THE INVESTOR'S SHORT LIST @AUTHOR: MA.XIAOHUI
		

		$collection_shortlist = $businessEntity->getSpecialEntity ( 'list' )->getCollection ();
		$collection_shortlist->addFieldToFilter ( 'list_table.user_id', $user->id );
		$data_shortlist = $collection_shortlist->getItems ();
		$this->view->data_shortlist = $data_shortlist;
	
	}
	
	public function investorProfileAction() {
		$user = Zend_Auth::getInstance ()->getIdentity ();
		$businessEntity = new Bbling_Model_Entity_Business ();
		
		$collection = $businessEntity->getSpecialEntity ( 'list' )->getCollection ();
		$collection->addFieldToFilter ( 'list_table.user_id', $user->id );
		$data = $collection->getItems ();
		
		$industryTypes = $businessEntity->getSpecialType ( 'industry', true, true, 'All' );
		$stateTypes = $businessEntity->getSpecialType ( 'state', true, true, 'please choose:' );
		$locations = $businessEntity->getSpecialType ( 'location', true, true, 'please choose:', 'location' );
		$fundTypes = $businessEntity->getFundList ();
		
		$this->view->user = $user;
		$this->view->data = $data;
		$this->view->locations = $locations;
		$this->view->fundTypes = $fundTypes;
		$this->view->stateTypes = $stateTypes;
		$this->view->industryTypes = $industryTypes;
	}
	
	public function entrepreneurProfileAction() {
	
	}
	
	public function ajaxGetBalanaceDataAction() {
		$user = Zend_Auth::getInstance ()->getIdentity ();
		$month = $this->getRequest ()->getParam ( 'month' );
		$id = $this->getRequest ()->getParam ( 'id' );
		$businessEntity = new Bbling_Model_Entity_Business ();
		if ($id) {
			$businessEntity->load ( $id );
		} else {
			$businessEntity->load ( $user->id, 'user_id' );
		}
		
		$BalanaceEntity = new Bbling_Model_Entity_Balanace ();
		if ($month) {
			$option ['month'] = $month;
			$option ['financial_id'] = $businessEntity->financial_id;
			$data = $BalanaceEntity->getBalanaceMonthData ( $option );
		} else {
			$data = $BalanaceEntity->getBalanaceData ( $businessEntity->financial_id );
		}
		
		echo Zend_Json::encode ( $data );
		exit ();
	}
	
	/*JUST FOR TEST*/
	public function aAction() {
		$emailHelper = new Evebit_Email_Helper ();
		$emailHelper->sendGoogleMail ( 'Google', 'Google gmail', '853807856@qq.com' );
		exit ();
	}
	
	public function bAction() {
		mail ( '853807856@qq.com', 'Google', 'Google gmail' );
		exit ();
	}
	
	public function newsTrickerAction() {
		$entity = new Bbling_Model_Entity_News ();
		$this->view->newsList = $entity->getAllNews ();
		$render = new Zend_Controller_Action_Helper_ViewRenderer ( $this->view );
		$render->renderScript ( 'index/news-tricker.phtml' );
		$content = $this->_response->getBody ();
		echo $content;
		exit ();
	}
	
	/* JUST FOR TEST */
	public function hmacAction() {
		//NOT RENDER , NO LAYOUT
		$this->_helper->viewRenderer->setNoRender ( true );
		$this->_helper->layout->disableLayout ();
		
		$hmac = new Evebit_Crypt_Hmac ();
		$arr = array ('filename' => 'newfile.txt' );
		//var_dump($hmac);
		//$param = $hmac->createParam($arr);
		//echo $param;
		$arr2 = array ('filename' => 'newfile.txt', 'hash' => '916ff2b5bbd949e5bb9956d5d5e58790' );
		$result = $hmac->verify_param ( $arr2 );
		if ($result) {
			echo 'yes';
		}
	}
	
	/*JUST FOR GOOGLE CHART TEST*/
	public function financialPlanDataAction() {
		//NOT RENDER , NO LAYOUT
		$this->_helper->viewRenderer->setNoRender ( true );
		$this->_helper->layout->disableLayout ();
		
		$financial_plan_chart_1 = array (array ('Jan', 1000 ), array ('Feb', 1100 ), array ('Mar', 1200 ), array ('April', 1300 ), array ('May', 2000 ), array ('June', 3000 ), array ('July', 4000 ), array ('Aug', 5000 ), array ('Sept', 100 ), array ('Oct', 200 ), array ('Dec', 1000 ) );
		
		$financial_plan_chart_2 = array (array ('Jan', 1000 ), array ('Feb', 1000 ), array ('Mar', 1000 ), array ('April', 1000 ), array ('May', 1000 ), array ('June', 1000 ), array ('July', 1000 ), array ('Aug', 1000 ), array ('Sept', 1000 ), array ('Oct', 1000 ), array ('Dec', 1000 ) );
		
		$financial_plan_chart_data = array ('financial_plan_chart_1' => $financial_plan_chart_1, 'financial_plan_chart_2' => $financial_plan_chart_2 );
		
		echo Zend_Json::encode ( $financial_plan_chart_data );
	}
	
	public function ajaxGetPlanIntruductionAction() {
		$name = $this->getRequest ()->getParam ( 'name' );
		$entity = new Bbling_Model_Entity_Intruduction ();
		$result = $entity->getPlanIntruduction ( $name );
		
		echo $result;
		exit ();
	}
}
